import React, { Component } from 'react';

interface IProps { }
interface IStates {
    component: any
}
// 懒加载
export function lazyLoad(componentfn: any) {
    return class LazyloadComponent extends Component<IProps, IStates> {
        constructor(props: IProps) {
            super(props);
            this.state = {
                component: null
            }
        }
        public async componentDidMount() {
            const { default: component } = await componentfn();
            this.setState({ component })
        }
        public render() {
            const C = this.state.component;
            return C ? <C {...this.props} /> : null;
        }
    }
}